package com.hx.xiao.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hx.xiao.entity.Hou;
import com.hx.xiao.mapper.HouMapper;
import com.hx.xiao.service.IHouService;
import freemarker.template.utility.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author hx
 * @since 2024-03-21
 */
@Service
public class HouServiceImpl extends ServiceImpl<HouMapper, Hou> implements IHouService {

    @Autowired
    private HouMapper houMapper;

    @Override
    public int insertL(Integer id) {
        UpdateWrapper<Hou> updateWrapper = new UpdateWrapper<>();
        updateWrapper.eq("id",id);
        updateWrapper.setSql("history=history+1");
        return  houMapper.update(null, updateWrapper);
    }

    @Override
    public List<Hou> fingAllText(String komg) {
        QueryWrapper<Hou> queryWrapper = new QueryWrapper<>();
        if (komg!=null && komg!=""){
            queryWrapper.eq("komg",komg);
        }
        return houMapper.selectList(queryWrapper);
    }

    @Override
    public List<Hou> byAll(Hou hou) {
        LambdaQueryWrapper<Hou> queryWrapper = new LambdaQueryWrapper<>();
        if (hou.getBiaoti()!=null && hou.getBiaoti()!=""){
            queryWrapper.like(Hou::getBiaoti,hou.getBiaoti());
        }
        if (hou.getZtext()!=null && hou.getZtext()!=""){
            queryWrapper.like(Hou::getZtext,hou.getZtext());
        }
        if (hou.getKomg()!=null && hou.getKomg()!=""){
            queryWrapper.eq(Hou::getKomg,hou.getKomg());
        }
        if (hou.getCtime()!=null && hou.getCtime()!=""){
            LocalDate date = LocalDate.now().minusDays(Integer.parseInt(hou.getCtime()));
            queryWrapper.ge(Hou::getCtime,date);
        }
        return houMapper.selectList(queryWrapper);
    }

    @Override
    public Hou findByid(Integer id) {
        return houMapper.selectById(id);
    }

    @Override
    public int updateByCollect(String history, int id) {
        return houMapper.updateByCollect(history,id);
    }

    @Override
    public List<Hou> fingAllHistory(Integer id) {
        return houMapper.findAllHistory(id);
    }

    @Override
    public List<Hou> fingAllCollect(Integer id) {
        return houMapper.findAllCollect(id);
    }

    @Override
    public List<Hou> fingName(String biaoti) {
        return houMapper.findName(biaoti);
    }

    @Override
    public List<Hou> findAllKome(String komg) {

        return houMapper.findAllKome(komg);
    }

    @Override
    public int updateB(Hou hou) {
        return houMapper.updateB(hou);
    }

    @Override
    public int deteleB(Integer id) {
        return houMapper.deleteB(id);
    }

    @Override
    public int insertB(Hou hou) {
        return houMapper.insertB(hou);
    }
}
